package com.edu.exam.enums.monitoring;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 巡检任务优先级等级枚举
 *
 * 管理巡检任务的优先级分类，包括低、普通、高、紧急等级
 *
 * @author System
 * @version 1.0.0
 */
public enum PatrolTaskPriorityLevel implements BaseEnum {

    /**
     * 低优先级
     */
    LOW("LOW", "低"),

    /**
     * 普通优先级
     */
    NORMAL("NORMAL", "普通"),

    /**
     * 高优先级
     */
    HIGH("HIGH", "高"),

    /**
     * 紧急优先级
     */
    URGENT("URGENT", "紧急");

    private final String code;
    private final String description;

    PatrolTaskPriorityLevel(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static PatrolTaskPriorityLevel fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Patrol task priority level code cannot be null or empty");
        }

        for (PatrolTaskPriorityLevel level : values()) {
            if (level.getCode().equals(code)) {
                return level;
            }
        }
        throw new IllegalArgumentException("Unknown patrol task priority level code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static PatrolTaskPriorityLevel fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("Patrol task priority level description cannot be null or empty");
        }

        for (PatrolTaskPriorityLevel level : values()) {
            if (level.getDescription().equals(description)) {
                return level;
            }
        }
        throw new IllegalArgumentException("Unknown patrol task priority level description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}